﻿package app.view.components.sections.children 
{
	import app.model.RemoteProxy;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	/**
	 * 2 ДЕТИ
	 * firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class ChildrenMBase extends LabeledSectionBase
	{
		// app.view.components.sections.children.ChildrenMBase
		
		public var childrenCompetitionBtn:GlamurBtnBase;
		public var childrenWorldBtn:GlamurBtnBase;
		
		public var forsiteProject_Btn:GlamurBtnBase;
		public var gorodTalantov_Btn:GlamurBtnBase;
		
		private var _image:Image;
		
		private var _btns:/*GlamurBtnBase*/Array;
		
		public function ChildrenMBase() 
		{
			super();
		}
		
		override protected function init():void 
		{
			super.init();
			
			_btns = [childrenCompetitionBtn, childrenWorldBtn, forsiteProject_Btn,gorodTalantov_Btn];
			//trace('init : ' + _btns);
		};
		
		private function build():void
		{
			_image = new Image(1680, 1050, Image.RESIZE_NONE, Image.ALIGN_NONE, 0, 0, false, 1, false);
			addChildAt(_image,0);
			////trace('url',RemoteProxy.DOMEN+_data.data.flash[1].flash[1].flash_path);
			if (_data) 
			{
				if (_data.data.flash[1].flash[1].flash_path!=undefined && _data.data.flash[1].flash[1].flash_path!='') 
				{
					_image.loadImage(RemoteProxy.DOMEN+_data.data.flash[1].flash[1].flash_path);
				};
			};
			
		};
		
		private function setEvents():void
		{
			childrenCompetitionBtn.addEventListener(MouseEvent.CLICK, onClickCompetitionBtn);
			childrenWorldBtn.addEventListener(MouseEvent.CLICK, onClickChildrenWorld);
			forsiteProject_Btn.addEventListener(MouseEvent.CLICK, onClickForsiteProject);
			gorodTalantov_Btn.addEventListener(MouseEvent.CLICK, onClickGorodTalantov);
			
			for (var i:int = 0; i < _btns.length; i++) 
			{
				_btns[i].addEventListener(MouseEvent.ROLL_OVER, onRollOver);
				_btns[i].addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}
		}
		
		private function onRollOver(e:MouseEvent):void 
		{
			Mouse.show();
			
		}
		
		private function onRollOut(e:MouseEvent):void 
		{
			Mouse.hide();
			
		}
		
		private function removeEvents():void
		{
			childrenCompetitionBtn.removeEventListener(MouseEvent.CLICK, onClickCompetitionBtn);
			childrenWorldBtn.removeEventListener(MouseEvent.CLICK, onClickChildrenWorld);
			forsiteProject_Btn.removeEventListener(MouseEvent.CLICK, onClickForsiteProject);
			gorodTalantov_Btn.removeEventListener(MouseEvent.CLICK, onClickGorodTalantov);
			
			
			for (var i:int = 0; i < _btns.length; i++) 
			{
				_btns[i].removeEventListener(MouseEvent.ROLL_OVER, onRollOver);
				_btns[i].removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			childrenCompetitionBtn.destroy();
			childrenWorldBtn.destroy();
			forsiteProject_Btn.destroy();
			gorodTalantov_Btn.destroy();
			
			if (_image)
			{
				_image.destroy();
				removeChild(_image);
				_image = null;
			}
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			childrenCompetitionBtn.setLang(data.lang);
			childrenWorldBtn.setLang(data.lang);
			forsiteProject_Btn.setLang(data.lang);
			gorodTalantov_Btn.setLang(data.lang);
			
			
			setEvents();
			
			build();
			//trace('data!!!',_data.data);
		};
		
		/**
		 * переходим конкурс детского рисунка
		 * @param	e
		 */
		private function onClickCompetitionBtn(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_COMPETITION_STAGES;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * переходим в дети мира о лучшем городе
		 * @param	e
		 */
		private function onClickChildrenWorld(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_30_RESEARCH;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * переход в форсайт проект
		 * @param	e
		 */
		private function onClickForsiteProject(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_FORSITE_PROJECT;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * переход в город талантов
		 * @param	e
		 */
		private function onClickGorodTalantov(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_CITY_TALANTS;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		
	}

}